<?php

namespace app\admin\model;

use think\Db;
use think\Model;

class AgentModel extends Model
{

    // 设置数据表（不含前缀）
    protected $name = 'agent_data';
    // 设置当前模型对应的完整数据表名称
    protected $table = 'ld_agent_data';

    public function __construct($data = [])
    {
        parent::__construct($data);
    }


    /**
     * @param $data
     * @param 添加信息
     */
    public function polist($data){
        $query = Db::name($this->name)->insert($data);
        return $query;
    }


    /**
     * @param 获取信息列表
     */
    public function problist($where,$page,$limit){
        $query = Db::name($this->name)->where($where)->page($page)->limit($limit)->order('id desc')->field('id,titile,content,enable,addTime,updateTime')->select();
        return $query;
    }


    /**
     * @param $id
     * @param 获取当前信息
     */
    public function datalist($id){
        $query = Db::name($this->name)->where('id',$id)->find();
        return $query;
    }


    /**
     * @param $where
     * @param $data
     * @param 修改信息
     */
    public function edisont($where,$data){
        $query = Db::name($this->name)->where($where)->update($data);
        return $query;
    }


    /**
     * @param $where
     * @param 获取当前信息状态
     */
    public function exbut($where){
        $query = Db::name($this->name)->where($where)->find();
        return $query;
    }


    /**
     * @param $where
     * @param $data
     * @param 信息禁用、启用
     */
    public function eidtion($where,$data){
        $query = Db::name($this->name)->where($where)->update($data);
        return $query;
    }


    /**
     * @param $id
     * @param 删除信息
     */
    public function del($id){
        $query = Db::name($this->name)->where('id',$id)->delete();
        return $query;
    }


    /**
     * @param 前台获取代理信息
     */
    public function webagent($where){
        $list = Db::name($this->name)->where($where)->order('id desc')->field('id,titile,addTime')->paginate(4,false);
        $page = $list->render();
        return array("list"=>$list,"page"=>$page);
    }


    /**
     * @param $where
     * @param 前台获取代理内容
     */
    public function dlsist($where){
        $query = Db::name($this->name)->where($where)->field('titile,content')->find();
        return $query;
    }

    /**
     * @param $where
     * @param $pust
     * @return mixed
     * @param 总条数
     */
    public function county($where){
        $query = Db::name($this->name)->where($where)->count();
        return $query;
    }

}